package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.WorkflowBusinessUserRel;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.WorkflowBusinessUserRelDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2020-12-08 10:50:35
 */
public class WorkflowBusinessUserRelConverts {

    private static Logger LOG = LoggerFactory.getLogger(WorkflowBusinessUserRelConverts.class);

    public static List<WorkflowBusinessUserRelDTO> convert(List<WorkflowBusinessUserRel> workflowBusinessUserRelList) {
        if (CollectionUtils.isEmpty(workflowBusinessUserRelList)) {
            return Collections.EMPTY_LIST;
        }

        List<WorkflowBusinessUserRelDTO> workflowBusinessUserRelListResult = Lists.newArrayList();
        for (WorkflowBusinessUserRel workflowBusinessUserRel : workflowBusinessUserRelList) {
            workflowBusinessUserRelListResult.add(convert(workflowBusinessUserRel));
        }
        return workflowBusinessUserRelListResult;
    }

    public static WorkflowBusinessUserRelDTO convert(WorkflowBusinessUserRel workflowBusinessUserRel) {
        try {
            return BeanUtils.copy(workflowBusinessUserRel, WorkflowBusinessUserRelDTO.class);
        } catch (Exception e) {
            LOG.error("WorkflowBusinessUserRel到WorkflowBusinessUserRelDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "WorkflowBusinessUserRel到WorkflowBusinessUserRelDTO转换失败", e);
        }
    }

    public static WorkflowBusinessUserRel convert(WorkflowBusinessUserRelDTO workflowBusinessUserRelDTO) {
        try {
            return BeanUtils.copy(workflowBusinessUserRelDTO, WorkflowBusinessUserRel.class);
        } catch (Exception e) {
            LOG.error("WorkflowBusinessUserRelDTO到WorkflowBusinessUserRel转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "WorkflowBusinessUserRelDTO到WorkflowBusinessUserRel转换失败", e);
        }
    }
}